package cn.iocoder.yudao.module.tms.service.companybaseinfo;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.tms.controller.admin.companybaseinfo.vo.*;
import cn.iocoder.yudao.module.tms.dal.dataobject.companybaseinfo.CompanyBaseInfoDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.tms.dal.mysql.companybaseinfo.CompanyBaseInfoMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.tms.enums.ErrorCodeConstants.*;

/**
 * 公司基本信息 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class CompanyBaseInfoServiceImpl implements CompanyBaseInfoService {

    @Resource
    private CompanyBaseInfoMapper companyBaseInfoMapper;

    @Override
    public Long createCompanyBaseInfo(CompanyBaseInfoSaveReqVO createReqVO) {
        // 插入
        CompanyBaseInfoDO companyBaseInfo = BeanUtils.toBean(createReqVO, CompanyBaseInfoDO.class);
        companyBaseInfoMapper.insert(companyBaseInfo);

        // 返回
        return companyBaseInfo.getId();
    }

    @Override
    public void updateCompanyBaseInfo(CompanyBaseInfoSaveReqVO updateReqVO) {
        // 校验存在
        validateCompanyBaseInfoExists(updateReqVO.getId());
        // 更新
        CompanyBaseInfoDO updateObj = BeanUtils.toBean(updateReqVO, CompanyBaseInfoDO.class);
        companyBaseInfoMapper.updateById(updateObj);
    }

    @Override
    public void deleteCompanyBaseInfo(Long id) {
        // 校验存在
        validateCompanyBaseInfoExists(id);
        // 删除
        companyBaseInfoMapper.deleteById(id);
    }

    @Override
        public void deleteCompanyBaseInfoListByIds(List<Long> ids) {
        // 删除
        companyBaseInfoMapper.deleteByIds(ids);
        }


    private void validateCompanyBaseInfoExists(Long id) {
        if (companyBaseInfoMapper.selectById(id) == null) {
          // throw exception(COMPANY_BASE_INFO_NOT_EXISTS);
        }
    }

    @Override
    public CompanyBaseInfoDO getCompanyBaseInfo(Long id) {
        return companyBaseInfoMapper.selectById(id);
    }

    @Override
    public PageResult<CompanyBaseInfoDO> getCompanyBaseInfoPage(CompanyBaseInfoPageReqVO pageReqVO) {
        return companyBaseInfoMapper.selectPage(pageReqVO);
    }

}